/* 
* @Author: LDF QQ 47121862
* @Date:   2014-06-12 19:08:53
* @Last Modified by:   LDF QQ 47121862
* @Last Modified time: 2014-06-13 10:03:44
*/

$(function (){
	$('.ainput').dblclick(function(event) {
		ajaxForm($(this));
	});
	var addHtml=$('#add').clone();
	$('#add').remove();
	$('.Menu ._add').click(function(){
		
		$.msg({
			str:addHtml.html(),
			timeout:5000,
			shade:1,
			closebtn:1
		})
			//添加表单提交时候
			$('form').submit(function(){
				var form=$(this),url=form.attr('action');
				$.post(url,form.serialize(),function(re){
					if(re=='1'){
						$.msg({timeout:0}).close();
						$.msg({str:'添加成功!',close:function(){
								location.reload()
							}})
					}else{
						$.msg({str:'添加失败'}).close();
					}
				})
				return false;
			})
		return false;
	})
	//删除弹出确认框
	$('._dels').click(function(){
		var id=$(this),h = id.attr('href');
		if(confirm('确认删除吗?')){
			$.post(h,{lid:id.attr('lid')},function(re){
				if(re=='1'){
					$.msg({str:'删除成功...',close:function(){
						location.reload();
					}})
				}else{
					$.msg({str:' :( 删除失败'})
				}
			})
		}
		return false;
	})
})

//---------------------ajax修改表单内容
function ajaxForm(id){
	var url=id.attr('post'),lid=id.attr('lid'),_name=id.attr('_name'),val=id.text(),old=id.clone(),
		h='<input class="pct90 p5 green b" name="'+_name+'" value="'+val+'" type="text">';
	id.html(h);
	var input=$('[name='+_name+']');
	input.focus();
	input.blur(function(){
		$.post(url,{lid:lid,name:_name,val:$(this).val()},function(re){
			(re=='1')?$.msg({str:'<b class="f22"><i class="icon-star icon-spin green mr10 icon-large"></i>成功...</b>'}):$.msg({str:'<b class="red">失败...</b>'});
		})
		$(this).remove();
		id.html($(this).val())
	})
}

